$(document).ready(function(){ 

  /* $("#send").click(function() {

	var login = $("#login").val();
	var pwd = $("#pwd").val();
	
     	if(login != "" && pwd != "")
	{
        	$.post('login.php', {login:login, pwd:pwd}, function(data){
			$("body").html(data);
		});
	}
	else
	{
        	alert("login or passord must not be empty");
		window.location='/';
	}
   });

      $("#create").click(function() {
      // alert("ok");
        var login = $("#login").val();
        var pwd = $("#pwd").val();

        if(login != "" && pwd != "")
        {
                $.post('create-account.php', {login:login, pwd:pwd}, function(data){
                        $("body").html(data);
                });
        }
        else
        {
                alert("login or passord must not be empty");
                 window.location='account.php';
        }
   });*/

   $("#filter").keyup(function() {
	var filter = $("#filter").val();
	var i=1;
	
	var tab = new Array;
	var select = $("#select").val();		   
	$.getJSON( "/log/log.json", function( data ) {
			 
	tab[0] = "<table style='width:95%;'><thead class='ui-btn-active ui-state-persist'><tr><th >Date</th><th>Heure</th> <th>Level</th><th>Application</th><th>Message</th></tr></thead><tbody>";
			
        var i=1;
        var test;
        $.each( data, function( key, val ) {
        	$.each( val, function( key2, val2 ) {
			if(select==1)
				test = val2.date.search(filter);
			else if(select==2)
				test = val2.heure.search(filter);
			else if(select==3)
				test = val2.level.search(filter);
			else if(select==4)
				test = val2.appli.search(filter);

			if(test !== -1)
				tab[i] = "<tr><td>" + val2.date + "</td><td >" + val2.heure + "</td><td>" + val2.level + "</td><td>" + val2.appli + "</td><td>" + val2.message + "</td></tr>";
                               	 i++;
                                });
                        });
			 tab[i++] = "</tbody><tfoot><tr><td colspan='6'><span><BR /></span></td></tr></tfoot></table>";
			
			$("#logs").html(tab);
                });
   });

});
